<!--
描述：考场管理信息组件
开发人：hqj
开发日期：2019年3月11日
修改人：
修改日期：
-->
<template lang="pug">
  keep-alive
    kalix-table(bizKey="examRoom" title='考场管理信息列表' v-bind:targetURL="targetURL"
    v-bind:bizDialog="bizDialog" v-bind:bizSearch="'ExamRoomSearch'" v-bind:btnList="btnList" v-bind:dictDefine="dictDefine"
    v-bind:toolbarBtnList="toolbarBtnList" v-bind:customToolBar="customToolBar" v-bind:isFixedColumn="isFixedColumn"
    v-on:afterDialogClose="dialogClose" ref="kalixTable")
      template(slot="tableColumnSlot")
        el-table-column(prop="subjectValName" label="考试科目" align="center" width="120px")
        el-table-column(prop="roomName" label="考场编号" align="center" width="120px")
        el-table-column(prop="seatNo" label="座位号" align="center" width="80px")
        el-table-column(prop="examCardNumber" label="准考证号" align="center" width="120px")
        el-table-column(prop="idCards" label="身份证号" align="center" width="120px")
        el-table-column(prop="name" label="姓名" align="center" width="120px")
        el-table-column(prop="attendName" label="成绩备注" align="center" width="80px")
</template>

<script type="text/ecmascript-6">
  import FormModel from './model'
  import {ExamRoomToolButtonList, ExamRoomURL} from '../config.toml'

  export default {
    name: 'kalix-exam-examroom',
    data() {
      return {
        formModel: Object.assign({}, FormModel),
        dictDefine: [{
          cacheKey: 'ENROLMENT-DICT-KEY',
          type: '考试科目',
          targetField: 'subjectValName',
          sourceField: 'subjectVal'
        }, {
          cacheKey: 'ENROLMENT-DICT-KEY',
          type: '考场编号',
          targetField: 'roomName',
          sourceField: 'room'
        }, {
          cacheKey: 'ENROLMENT-DICT-KEY',
          type: '成绩备注',
          targetField: 'attendName',
          sourceField: 'attend'
        }],
        btnList: ExamRoomToolButtonList,
        toolbarBtnList: [
          {id: 'importExcel', title: '导入Excel', isShow: true, icon: 'icon-add'}
        ],
        targetURL: ExamRoomURL,
        bizDialog: [
          {id: 'edit', dialog: 'ExamRoomAdd'},
          {id: 'add', dialog: 'ExamRoomAdd'},
          {id: 'importExcel', dialog: 'ExamRoomImport'}
        ],
        isFixedColumn: true
      }
    },
    components: {},
    created() {
    },
    activated() {
    },
    deactivated() {
    },
    computed: {
      // jsonStr() {
      //   return '{"delFlag": "0", "creationDate:begin:gt": "' + this.currentDateYear +
      //     '-01-01 00:00:00", "creationDate:end:lt": "' + this.currentDateYear + '-12-31 23:59:59"}'
      // },
      // appendCondition() {
      //   return {
      //     'delFlag': '0', 'creationDate:begin:gt': this.currentDateYear +
      //     '-01-01 00:00:00', 'creationDate:end:lt': this.currentDateYear + '-12-31 23:59:59'
      //   }
      // }
    },
    methods: {
      customToolBar(btnId, table) {
        switch (btnId) {
          case 'importExcel': {
            this.onImportExcel(table)
            break
          }
          // case 'exportExcel': {
          //   this.onExportExcel(table)
          //   break
          // }
          // case 'downloadExcel': {
          //   let excelName = ChoiceTName
          //   //excelName = encodeURI(excelName)
          //   window.open(this.$KalixGlobalConfig.baseURL + TemplatePath
          //     + '&filename=' + excelName + '&access_token=' + this.$KalixCatch.get('access_token'))
          //   break;
          // }
        }
      },
      onImportExcel(table) {
        let dig =
          table.bizDialog.filter((item) => {
            return item.id === 'importExcel'
          })
        table.whichBizDialog = dig[0].dialog
        setTimeout(() => {
          table.$refs.kalixDialog.$refs.kalixBizDialog.open('批量导入', false, '')
        }, 20)
      },
      // onExportExcel(table) {
      //   const loading = this.$loading({
      //     lock: true,
      //     text: 'Excel数据导出中...',
      //     spinner: 'el-icon-loading',
      //     background: 'rgba(255, 255, 255, 0.7)'
      //   })
      //   let queryParams = table.getQueryParams()
      //   this.axios.request({
      //     headers: {
      //       'Content-Type': 'application/x-www-form-urlencoded'
      //     },
      //     method: 'get',
      //     baseURL: '../api',
      //     url: ExportExlURL,
      //     responseType: 'blob',
      //     params: {
      //       jsonStr: queryParams,
      //       EntityName: 'com.kalix.middleware.excel.api.model.ChoiceDto',
      //       ServiceUrl: '/choices/export/list',
      //       serviceDictUrl: '/enrolment/dicts/types/values'
      //     }
      //   }).then(response => {
      //     if (response.data) {
      //       this.download(response.data)
      //       this.$KalixMessage.success('导出成功！')
      //     } else {
      //       this.$KalixMessage.error('导出失败！')
      //     }
      //     loading.close();
      //   }).catch((e) => {
      //     this.$KalixMessage.error('导出失败！原因：' + e.message)
      //     loading.close();
      //   })
      // },
      // download(data) {
      //   let url = window.URL.createObjectURL(new Blob([data]))
      //   let link = document.createElement('a')
      //   link.style.display = 'none'
      //   link.href = url
      //   link.setAttribute('download', '选择题试题.xlsx')
      //   document.body.appendChild(link)
      //   link.click()
      // },
      dialogClose() {
        this.$refs.kalixTable.refresh()
      }
    }
  }
</script>

<style scoped lang="stylus">
</style>
